|
![](/i/fill.gif) |
ingo wrote in message ...
>I'm looking for a macro that returns a value based on an input value
>(Val) within a given input range (iMin to iMax), the ReturnVal has to
>be in the range oMin, oMax.
>Kind of like the "how to create random numbers in a range other than 0
>to 1". But then with a arbitrary input range.
Here you are:
#macro RVal(iMin, iMax, Val, oMin, oMax)
#local v = (Val - iMin) / (iMax - iMin);
(oMin + (oMax - oMin) * v)
#end
The first line gives you a [0,1] value and the second "returns" the result.
E.g.
#declare qqq = RVal(0., 1., .4, 10, 20);
which expanded becomes:
#declare qqq = (10 + (20 - 10) * (.4 - 0) / (1 - 0));
(If I got the parenthesis right!!!)
BTW, ALWAYS put between () the return value, otherwise calls like this would
be wrong:
RVal(....) * 10
which has to be (...) * 10 and NOT oMin + (oMax - oMin) * v *10!
Bye!!!
Alessandro Coppo
P.S: have a look at POVRay documentation, this function call/procedure call
hybrid nature is well explained in #macro help.
Post a reply to this message
|
![](/i/fill.gif) |